{block name='content'}
<form class="layui-form layui-card" lay-filter="lay_form" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">
    <div class="layui-card-body padding-40">
        <div class="layui-form-item layui-row layui-col-space15">
            <div class="layui-col-xs12 block relative">
                <span class="color-green label-required-prev">设备柜点</span><span class="margin-left-5 color-desc">Device Type</span>
                <select class="layui-select" lay-verify="required" lay-search lay-filter="store_id" name="store_id">
                    <option selected value="">请选择 设备柜点</option>
                    {foreach $stores as $row}
                    <option value="{$row['id']}">{$row['name']}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-space15">
            <label class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">中途取物</span><span class="margin-left-5 color-desc">Pick up on the way</span><br>
                <div class="layui-input-inline">
                    {assign name="half_type" value="$vo.half_type|default=1"}
                    <input type="radio" name="half_type" value="1" title="允许" {if $half_type==1}checked{/if}>
                    <input type="radio" name="half_type" value="0" title="不允许" {if $half_type!=1}checked{/if}>
                </div>
            </label>
            <label class="layui-col-xs6 block relative">
                <span class="color-green">中途取物时长</span><span class="margin-left-10 color-red">PS：允许中途取物有效</span><br>
                <select class="layui-select half_hour" required lay-search lay-filter="half_hour" name="half_hour">
                    {php}$fee_type = isset($vo['fee_type'])?$vo['fee_type']:0; $a = $fee_type==3?0:0.1; $half_hour = $vo['half_hour']??1.0; {/php}
                    {for start="$a" end="30.1" name="i" step="0.1"}
                    {php}$title = $fee_type==3 && $i<0.1?'不限时长':$i.'小时';{/php}
                    {if round($half_hour,1) eq round($i,1)}
                    <option selected value="{$i}">{$title}</option>
                    {else}
                    <option value="{$i}">{$title}</option>
                    {/if}
                    {/for}
                </select>
            </label>
        </div>
        <div class="layui-form-item relative block">
            <span class="color-green font-w7 label-required-prev">柜点柜子</span>
            <span class="color-desc margin-left-5">Device Name</span>
            <div class="layui-textarea">

            </div>
        </div>

        <div class="hr-line-dashed"></div>
        <input type='hidden' value='change' name='act'>

        <div class="layui-form-item text-center">
            <button class="layui-btn" lay-submit lay-filter="submit">保存数据</button>
            <button class="layui-btn layui-btn-danger" type='button' data-close="">取消编辑</button>
        </div>

    </div>

</form>
{/block}

{block name='script'}
<script>
    layui.form.render();

    layui.form.on('select(store_id)',function (data){
        $.post("{:url('getDevices')}", {store_id:data.value},function (info){
            $(".layui-textarea").empty();
            let tmp = ""
            let devices = info.devices;
            let fee_type = 0;
            for (x in devices){
                tmp += '<input checked name="d_id[]" title="'+devices[x].device_name+'" type="checkbox" value="'+devices[x].id+'">'
                fee_type = devices[x].fee_type;
            }
            $(".layui-textarea").append(tmp);

            if(fee_type===2){
                if($(".half_hour option:eq(0)").text()==='不限时长'){
                    $(".half_hour option:eq(0)").remove();
                }
            }else if(fee_type===3){
                if($(".half_hour option:eq(0)").text()==='0.1小时'){
                    $(".half_hour").prepend("<option value='0'>不限时长</option>");
                }
            }else{
                if($(".half_hour option:eq(0)").text()==='0.1小时'){
                    $(".half_hour").prepend("<option value='0'>不限时长</option>");
                }
            }


            layui.form.render();
        })
    });

</script>
{/block}